<?php
$INCLUDE_PATH = $INCLUDE_PATH ? $INCLUDE_PATH : "./";
require_once ($INCLUDE_PATH . "./inc/checkfun.php");
require_once ($INCLUDE_PATH . "./include/WebService2Db.php");
class CheckLogin {
//
// DB settings
//
    public  function checkLogin() {
        $adminname=$_COOKIE['adminname'];
        $adminpassword=$_COOKIE['adminpassword'];
        $adminlogintime=(int)$_COOKIE['adminlogintime'];
        if(!CheckFun::checkusername($adminname)) {
            die("<script>alert(\"温馨提示！用户名错误！\");location.href=\"../index.php\";</script>");
        }
        if(!CheckFun::checkpassword($adminpassword)) {
            die("<script>alert(\"温馨提示！密码错误！\");location.href=\"../index.php\";</script>");
        }
        $isuser = self::selectuser($adminname,$adminpassword);
        if ($isuser) {
            setcookie("adminname",$username);
            setcookie("adminpassword",$password);
            setcookie("adminlogintime",time());
            Y::$tpl->set("adminname",$username);

        }
        return true;

    }
    public  function selectuser($username,$password) {
        $DB=new DB_MYSQL;
        $DB->connect();
        $sql="SELECT *  FROM `".PRE."_user` WHERE `account` = '".$username."' AND `password` = '".$password."'";
        $query = $DB->query_first($sql);
        return $query;
    }
    public  function checkUserDegree() {
        $username=$_COOKIE['adminname'];
        $password=$_COOKIE['adminpassword'];
        $DB=new DB_MYSQL;
        $sql="SELECT *  FROM `".PRE."_user` WHERE `account` = '".$username."' AND `password` = '".$password."'";
        $query = $DB->query_first($sql,DB);
        setcookie("usertype",$query['user_type']);
        if ($query['user_type'] == 1)
        {
         return false;
        }
        return true;


    }

}

?>
